# 导包
import unittest
from api.employee import EmployeeAPI
# 创建类
from utils import common_assert


class TestEmployee(unittest.TestCase):
    employee_id = None

    # 前置处理
    def setUp(self):
        self.employee = EmployeeAPI()
    # 添加员工
    def test001_add_employee(self):
        add_employee_data = {
            "username": "jack070903",
            "mobile": "13212332172",
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "10080",
            "departmentName": "销售",
            "departmentId": "1266699057968001021",
            "correctionTime": "2020-07-30T16:00:00.000Z"
        }
        # 获取响应结果
        response = self.employee.add_employee(add_employee_data=add_employee_data)
        print(response.json())
        # 断言
        # self.assertEqual(200,response.statue_code)
        # self.assertEqual(True,response.json().get("success"))
        # self.assertEqual(10000,response.json().get("code"))
        # self.assertIn("操作成功！",response.json().get("message"))
        common_assert(self,response,200,True,10000,"操作成功！")
        # 提取员工ID
        TestEmployee.employee_id = response.json().get("data").get("id")
        print(TestEmployee.employee_id)
    # 修改员工
    def test002_update_employee(self):
        update_employee_data = {"username":"rose0709"}
        response = self.employee.update_employee(TestEmployee.employee_id,update_data=update_employee_data)
        # 断言
        common_assert(self, response)   #直接使用公共断言方法的默认值
    # 查询员工
    def test003_get_employee(self):
        response = self.employee.get_employee(TestEmployee.employee_id)
        # 断言
        common_assert(self, response, 200, True, 10000, "操作成功！")
    # 删除员工
    def test004_delete_employee(self):
        response = self.employee.delete_employee(TestEmployee.employee_id)
        # 断言
        common_assert(self, response, 200, True, 10000, "操作成功！")